﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using Ccit.Utils;

namespace Ccit.OA.NewsCenter
{
    #region  信息中心-栏目管理
    /// <summary>
    /// column manage bussiness deal 
    /// </summary>
    public class ColumnBLL
    {
        /// <summary>
        /// 树
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public List<MsColumn> GetTreeData(string type)
        {
            IColumn column = this.GetBllObj();
            List<MsColumn> mclist = column.GetBindTree(type);
            column = null;
            return mclist;
        }
        /// <summary>
        /// 获取单个对象
        /// </summary>
        /// <param name="columnId">主键</param>
        /// <returns></returns>
        public MsColumn GetMsColumnObj(string columnId)
        {
            IColumn column = this.GetBllObj();
            MsColumn mc = column.GetMsColumnObj(columnId);
            column = null;
            return mc;
        }
        /// <summary>
        /// 获取下拉列表
        /// </summary>
        /// <param name="type">信息类型</param>
        /// <returns></returns>
        public List<MsColumn> GetDropDownList(string type,string columnId)
        {
            IColumn column = this.GetBllObj();
            List<MsColumn> mclist = column.GetDropDownList(type,columnId);
            column = null;
            return mclist;
        }
        /// <summary>
        /// 判断是否有子类
        /// </summary>
        /// <param name="astLayCode"></param>
        /// <returns></returns>
        public bool isHasChildType(string columnCode)
        {
            IColumn column = this.GetBllObj();
            bool res = column.isHasChildType(columnCode);
            column = null;
            return res;
        }
         /// <summary>
        /// 获取所有子节点
        /// </summary>
        /// <param name="columnId">主键</param>
        /// <returns></returns>
        public List<MsColumn> GetSubColumnTypes(string columnId)
        {
            IColumn column = this.GetBllObj();
            List<MsColumn> mclist = column.GetSubColumnTypes(columnId);
            column = null;
            return mclist;
        }
        /// <summary>
        /// 获取父节点对象
        /// </summary>
        /// <param name="columnId">主键</param>
        /// <returns></returns>
        public MsColumn GetFatherObj(string columnId)
        {
            IColumn column = this.GetBllObj();
            MsColumn mc = column.GetFatherObj(columnId);
            column = null;
            return mc;
        }
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="mc"></param>
        /// <returns></returns>
        public List<string> InsertColumn(MsColumn mc)
        {
            IColumn column = this.GetBllObj();
            List<string> slist = column.InsertColumn(mc);
            column = null;
            return slist;
        }
        /// <summary>
        /// 删除节点
        /// </summary>
        /// <param name="columnId"></param>
        /// <returns></returns>
        public List<string> RemoveNode(string columnId)
        {
            IColumn column = this.GetBllObj();
            List<string> slist = column.RemoveNode(columnId);
            column = null;
            return slist;
        }


        public string GetNodeLevelStruct(string dtNodeId)
        {
            IColumn column = this.GetBllObj();
            string levelStruct = column.GetNodeLevelStruct(dtNodeId);
            column = null;
            return levelStruct;
        }
        #endregion

        #region 信息中心-信息查询
        /// <summary>
        /// get tree by browsepurview
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public List<MsColumn> GetColListByPurview(string type)
        {
            LoginUser loginUser = (LoginUser)HttpContext.Current.Session["LogUserInfo"];
            IColumn column = this.GetBllObj();            
            List < MsColumn > lstCol = column.GetSearchTree(type, loginUser);
            column = null;
            loginUser = null;
            return lstCol;
        }

        /// <summary>
        /// 获取所有子节点的层级编号
        /// </summary>
        /// <param name="columnId"></param>
        /// <returns></returns>
        public string GetChildLevelCode(string columnId)
        {
            IColumn column = this.GetBllObj();
            string childCodes = column.GetChildLevelCode(columnId);
            column = null;
            return childCodes;
        }

        #endregion

        /// <summary>
        /// 根据设置权限查询栏目
        /// </summary>
        /// <param name="whereClause"></param>
        /// <returns></returns>
        public string GetRangeColumn(string whereClause)
        {
            IColumn column = GetBllObj();
            string sColumnIds = column.GetRangeColumn(whereClause);
            column = null;
            return sColumnIds;
        }

        /// <summary>
        ///  获取所有子节点id
        /// </summary>
        /// <param name="columnCode"></param>
        /// <returns></returns>
        public string GetAllChildColId(string columnCode)
        {
            IColumn column = GetBllObj();
            string sChildColIds = column.GetAllChildColId(columnCode);
            column = null;
            return sChildColIds;
        }
        
        

        /// <summary>
        /// 获取当前用户具有管理权限的栏目
        /// </summary>
        /// <param name="Type"></param>
        /// <returns></returns>
        public List<MsColumn> GetColManage(string Type)
        {
            IColumn column = GetBllObj();
            List<MsColumn> lstColManage = column.GetColManage(Type);
            column = null;
            return lstColManage;
        }

        /// <summary>
        /// 获取当前用户具有发布权限的栏目
        /// </summary>
        /// <param name="Type"></param>
        /// <returns></returns>
        public List<MsColumn> GetColPub(string Type)
        {
            IColumn column = GetBllObj();
            List<MsColumn> lstColManage = column.GetColPub(Type);
            column = null;
            return lstColManage;
        }

        private IColumn GetBllObj()
        {
            IColumn column = (IColumn)Factory.CreateObject("Ccit.OA.NewsCenter.dll", "Ccit.OA.NewsCenter.Column", ImportComponentType.DotNetDll, null);
            return column;
        }
    }
}
